package com.itheima.demo7test;

import java.util.ArrayList;
import java.util.Scanner;

public class MoviesServe
{
    ArrayList<Movies> list = new ArrayList<>();
    //添加扫描器
    Scanner sc = new Scanner(System.in);
    public void Start()
    {
        while (true) {
            System.out.println("欢迎来到电影管理系统");
            System.out.println("1.添加电影");
            System.out.println("2.查看电影");
            System.out.println("3.删除电影");
            System.out.println("4.封杀明星");
            System.out.println("5.退出系统");
            String choice = sc.next();
            switch (choice)
            {
                case "1":
                    addMovies();
                    break; 
                case "2":
                    showMovies();
                    break;
                case "3":
                    removeMovies();
                     break;
                case "4":
                    removestar();
                     break;
                case "5":
                    return;
               default:
               System.out.println("输入错误");
                     break;
            }
        }
    }

    private void removestar() {
        System.out.println("请输入要封杀的明星");
        String name = sc.next();
        for(int i=0;i<list.size();i++)
        {
            Movies m = list.get(i);
            if(m.getActor().contains(name))
            {
                list.remove(i);
                System.out.println("封杀成功");
                i--;
            }
        }
    }

    private void showMovies() {
        System.out.println("请输入要搜索的电影");
        String name = sc.next();
        for(int i=0;i<list.size();i++)
        {
            Movies m = list.get(i);
            if(m.getName().equals(name))
            {
                System.out.println(m);
                return;
            }
        }
    }

    private void removeMovies() {
        System.out.println("请输入要删除的电影名称");
        String name = sc.next();
        for (int i = 0; i < list.size(); i++) {
            Movies m = list.get(i);
            if (m.getName().equals(name)) {
                list.remove(i);
                System.out.println("删除成功");
                return;
            }
        }
    }

    private void addMovies() {
        System.out.println("请输入电影名称");
        String name = sc.next();
        System.out.println("请输入电影评分");
        double score = sc.nextDouble();
        System.out.println("请输入主演");
        String actor = sc.next();
        System.out.println("请输入价格");
        double price = sc.nextDouble();
        Movies m = new Movies(name, score, actor, price);
        list.add(m);
    }
}
